package org.cloud.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.cloud.model.dto.PayDto;
import org.cloud.response.ResultData;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * ClassName: PayController
 * Package: org.cloud.controller
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/4/10 - 21:30
 * @Version: v1.0
 */
@Slf4j
@RestController
@RequestMapping("/consumer")
@RequiredArgsConstructor
public class AOrderController {

    /**
     * 先写死，硬编码
     */
    public static final String PaymentSrv_URL = "http://localhost:8001";

    private final RestTemplate restTemplate;

    /**
     * 一般情况下，通过浏览器的地址栏输入url，发送的只能是get请求
     * 我们底层调用的是post方法，模拟消费者发送get请求，客户端消费者
     * 参数可以不添加@RequestBody
     * @param payDTO
     * @return
     */
    @GetMapping("/pay/add")
    public ResultData addOrder(PayDto payDTO){
        return restTemplate.postForObject(PaymentSrv_URL + "/pay/add",payDTO,ResultData.class);
    }

    /**
     * @param orderNo
     * @return
     */
    @GetMapping("/pay/query/{orderNo}")
    public ResultData queryOrder(@PathVariable("orderNo") String orderNo){
        return restTemplate.getForObject(PaymentSrv_URL + "/pay/query/" + orderNo,ResultData.class);
    }
}
